package herramientas;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Agente_Properties {
	  private static String INPUT_FILE = "general.properties";
	  private Properties prProp= null;
	  private static Agente_Properties agente= null;
          private File file;
          private FileInputStream fIS;
          private FileOutputStream fos;
	  /**
	    * @param args
	    */
	  private Agente_Properties() throws FileNotFoundException, IOException{
		  prProp = new Properties();
                 //1. obtener fichero de configuraciÃ³n
                  file = new File(INPUT_FILE);
                 // file.setReadOnly();
                  fIS = new FileInputStream(file);
                  prProp.load(fIS);
  	  }
	  public static Agente_Properties getAgenteProperties() throws FileNotFoundException, IOException{
		 if(agente==null){
			 agente= new Agente_Properties();
		 }
		 return agente;
	  }
	  
	  public String getProperty(String key){
		  return prProp.getProperty(key);
	  }
	  
	  public void setProperty(String key, String valor) throws FileNotFoundException, IOException{
              prProp.setProperty(key, valor);
	  }
          public void guardar(){
        try {
            prProp.store(fos, "nada");
            fos.close();
        } catch (IOException ex) {
            Logger.getLogger(Agente_Properties.class.getName()).log(Level.SEVERE, null, ex);
        }
          }
          public void cerrar(){
        try {
            fIS.close();
        } catch (IOException ex) {
            Logger.getLogger(Agente_Properties.class.getName()).log(Level.SEVERE, null, ex);
        }
          }

}
